package com.base.balibrary.base;

import android.app.Application;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;

/**
 * BAndroid
 * Created by YichenZ on 2015/4/15 13:54.
 */
public class BaseApplication extends Application{

    //  Log提示
    public static final String LOGTAG="+BAndroid+\t";

    private static BaseApplication instance;

    public static BaseApplication getInstance(){ return instance; }

    //系统版本号以及版本名称
    public short currVerCode=0;
    public String currVerName;

    //当前模式是否为BUG模式
    public static final boolean BA_DEBUG=true;

    //程序信息
    private PackageInfo packageInfo;

    @Override
    public void onCreate() {
        super.onCreate();
        if(instance==null)
            instance = this;

        //设置版本名以及版本号
        if(currVerCode==0&&currVerName==null){
            try {
                packageInfo=getPackageManager().getPackageInfo(getPackageName(),0);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
            currVerCode=(short)packageInfo.versionCode;
            currVerName=packageInfo.packageName;
        }
    }

    /**
     * log
     * @param str
     */
    public static void logMessage(String str){
        logMessage(BA_DEBUG,str);
    }

    public static void logMessage(int str){
        logMessage(String.valueOf(str));
    }

    public static void logMessage(boolean str){
        logMessage(String.valueOf(str));
    }


    public static void logMessage(boolean flg,String str){
        if(flg) Log.v(LOGTAG, str);
    }

}
